package pw.yumc.Residence.commandmain;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cn.citycraft.PluginHelper.commands.BaseCommand;
import pw.yumc.Residence.ResidenceMain;

public class CommandResLoad extends BaseCommand {
    ResidenceMain plugin;

    public CommandResLoad(final ResidenceMain plugin) {
        super("resload");
        this.plugin = plugin;
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        if (!(sender instanceof Player) || plugin.getPermissionManager().isResidenceAdmin((Player) sender)) {
            try {
                plugin.reloadConfig();
                plugin.getConfigManager().load();
                plugin.loadYml();
                sender.sendMessage(ChatColor.GREEN + "[Residence] 从配置保存文件重新载入数据...");
            } catch (final Exception ex) {
                sender.sendMessage(ChatColor.RED + "[Residence] 无法从配置保存文件重新载入数据, 请查看控制台异常信息!");
                sender.sendMessage(ChatColor.RED + "[Residence] 异常: " + ex.getMessage());
                Logger.getLogger(ResidenceMain.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}
